package com.example.springcloud.utils;

/**
 * 用来统一返回数据的格式的实体工具类
 *
 * @param <T> 需要返回的数据
 */
public class ResultEntity<T> {

    // 响应状态码
    private Integer responseCode;
    // 信息
    private String message;
    // 需要返回的数据
    private T data;

    /**
     * Instantiates a new Result entity.
     *
     * @param responseCode the response code
     * @param message      the message
     * @param data         the data
     */
    public ResultEntity(Integer responseCode, String message, T data) {

        this.responseCode = responseCode;
        this.data = data;
        this.message = message;
    }

    /**
     * Instantiates a new Result entity.
     *
     * @param responseCode the response code
     * @param message      the message
     */
    public ResultEntity(Integer responseCode, String message) {

        this.message = message;
        this.responseCode = responseCode;
    }

    /**
     * Instantiates a new Result entity.
     *
     * @param responseCode the response code
     */
    public ResultEntity(Integer responseCode) {

        this.responseCode = responseCode;
    }

    /**
     * Instantiates a new Result entity.
     *
     * @param responseCode the response code
     * @param data         the data
     */
    public ResultEntity(Integer responseCode, T data) {

        this.data = data;
        this.responseCode = responseCode;
    }

    /**
     * Instantiates a new Result entity.
     *
     * @param message the message
     */
    public ResultEntity(String message) {

        this.message = message;
    }

    public ResultEntity(T data, String message, Integer responseCode) {

        this.data = data;
        this.message = message;
        this.responseCode = responseCode;
    }

    public ResultEntity(String message, Integer responseCode) {

        this.message = message;
        this.responseCode = responseCode;
    }

    public ResultEntity(T data, Integer responseCode) {

        this.data = data;
        this.responseCode = responseCode;
    }

    public ResultEntity(T data, String message) {

        this.data = data;
        this.message = message;
    }

    public ResultEntity() {

    }

    /**
     * 返回数据的通用方法
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param message      the message
     * @param data         the data
     * @return the result entity
     */
    public static <D> ResultEntity<D> commonResult(Integer responseCode, String message, D data) {

        return new ResultEntity<>(responseCode, message, data);
    }

    /**
     * 返回数据的通用方法
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param data         the data
     * @return the result entity
     */
    public static <D> ResultEntity<D> commonResult(Integer responseCode, D data) {

        return new ResultEntity<>(responseCode, data);
    }

    /**
     * 成功但不需要返回数据
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param message      the message
     * @return the result entity
     */
    public static <D> ResultEntity<D> successWithoutData(Integer responseCode, String message) {

        return new ResultEntity<>(responseCode, message);
    }

    /**
     * 成功但不需要返回数据
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @return the result entity
     */
    public static <D> ResultEntity<D> successWithoutData(Integer responseCode) {

        return new ResultEntity<>(responseCode);
    }

    /**
     * 成功并需要返回数据
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param message      the message
     * @param data         the data
     * @return the result entity
     */
    public static <D> ResultEntity<D> successWithData(Integer responseCode, String message, D data) {

        return new ResultEntity<>(responseCode, message, data);
    }

    /**
     * 成功并需要返回数据
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param data         the data
     * @return the result entity
     */
    public static <D> ResultEntity<D> successWithData(Integer responseCode, D data) {

        return new ResultEntity<>(responseCode, data);
    }

    /**
     * 失败并且没有数据返回
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @param message      the message
     * @return the result entity
     */
    public static <D> ResultEntity<D> failedWithoutData(Integer responseCode, String message) {

        return new ResultEntity<>(responseCode, message);
    }

    /**
     * 失败并且没有数据返回
     *
     * @param <D>          the type parameter
     * @param responseCode the response code
     * @return the result entity
     */
    public static <D> ResultEntity<D> failedWithoutData(Integer responseCode) {

        return new ResultEntity<>(responseCode);
    }

    public T getData() {

        return data;
    }

    public void setData(T data) {

        this.data = data;
    }

    public String getMessage() {

        return message;
    }

    public void setMessage(String message) {

        this.message = message;
    }

    public Integer getResponseCode() {

        return responseCode;
    }

    public void setResponseCode(Integer responseCode) {

        this.responseCode = responseCode;
    }

}
